\hypertarget{group__nxbot__sensors}{
\section{SENSORS Library}
\label{group__nxbot__sensors}\index{SENSORS Library@{SENSORS Library}}
}


PWM library for applying different velocities to the motors in NXBOT.  


\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__nxbot__sensors_ga1a0d280534953662003acd91f20071c1}{BATT\_\-READ\_\-VOLT}~0
\begin{DoxyCompactList}\small\item\em constant definition for battery\_\-read \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sensors_ga61262b004f6813b955f4d0b2d6553817}{BATT\_\-READ\_\-PERC}~1
\begin{DoxyCompactList}\small\item\em constant definition for battery\_\-read \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sensors_ga4ab82b3d018ff6e6866549a065188a30}{sensors\_\-getIR}()~ir\_\-read()
\item 
\#define \hyperlink{group__nxbot__sensors_ga704680c481c946bf98aeb484c46f30e0}{sensors\_\-getBumpers}()~bumpers\_\-read()
\item 
\#define \hyperlink{group__nxbot__sensors_gada5c769ceb7d8b75c54cf90ab4e748f7}{sensors\_\-getBattState}()~battery\_\-read(BATT\_\-READ\_\-PERC)
\item 
\#define \hyperlink{group__nxbot__sensors_ga709d68c36da1e3f2b5feec8c76ed9243}{sensors\_\-getBattVoltage}()~battery\_\-read(BATT\_\-READ\_\-VOLT)
\item 
\#define \hyperlink{group__nxbot__sensors_ga843e7932aafddffd58c4e7f2d4065bca}{sensors\_\-getSonar}(x, y, s)~sonar\_\-read(x,y,s)
\item 
\#define \hyperlink{group__nxbot__sensors_ga21d87617d11c161caa395ce84f987e71}{sensors\_\-setSonar}(x, u)~sonar\_\-write(x,u)
\item 
\#define \hyperlink{group__nxbot__sensors_ga756d8a8a2ba732eb8d918b48108bf034}{sensors\_\-getADCRead}(channel)~adc\_\-read(channel)
\item 
\#define \hyperlink{group__nxbot__sensors_gaa04e94731b959482fa4a5918529c9e16}{sensors\_\-setADCChannel}(channel)~adc\_\-setChannel(channel)
\item 
\#define \hyperlink{group__nxbot__sensors_ga4f69888f0b0485e1c303c271272dbecf}{sensors\_\-getDIO}()~dio\_\-read()
\item 
\#define \hyperlink{group__nxbot__sensors_ga3fece7b941ca3f7239a55747bd02ce48}{sensors\_\-setDIO}(val)~dio\_\-write(val)
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__nxbot__sensors_gabfbbfb986d008991dbbe32035cbdcde6}{battery\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Hardware initialization for the battery module. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__sensors_gabf908968d26d8f291a60846d6dd51251}{battery\_\-ledEnable} (unsigned char en)
\begin{DoxyCompactList}\small\item\em Function used to write the state of the battery-\/LED, located in the rear of NXBot. \item\end{DoxyCompactList}\item 
unsigned char \hyperlink{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState} (void)
\begin{DoxyCompactList}\small\item\em Reads the state of the battery, in \mbox{[}\%\mbox{]} units. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage} (void)
\begin{DoxyCompactList}\small\item\em Reads the state of the battery, in \mbox{[}V\mbox{]} units. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__nxbot__sensors_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} (unsigned char type)
\begin{DoxyCompactList}\small\item\em Read the state of the battery, wether voltage or percentage. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__sensors_gafbed7bde16bf6f2535f0792084773b17}{sensors\_\-readAll} (\hyperlink{structsensors__t}{sensors\_\-t} $\ast$sens)
\item 
void \hyperlink{group__nxbot__sensors_gac5ec1d578591899e43c3515d05e573b7}{sensors\_\-init} (void)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
PWM library for applying different velocities to the motors in NXBOT. 
\begin{DoxyCode}
 #include <sensors.h> 
\end{DoxyCode}
 This module uses timer0 of the ATmega1281 microcontroller for generating the desired PWM signals. Timer0 is configured in {\itshape Free Running mode\/}, and it is constantly compared with two registers (OC0 and OC1), in order to toggle the logical state of two pins, where the PWM signals to the motors are connected. Another two signals are used in order to set the desired direction of the motor. For FORWARD direction use {\bfseries positive} values, for BACKWARD direction use {\bfseries negative} values. This library does not need to have the interrupts in order to function correctly, it is not an interrupt-\/driven module. 

\subsection{Define Documentation}
\hypertarget{group__nxbot__sensors_ga61262b004f6813b955f4d0b2d6553817}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!BATT\_\-READ\_\-PERC@{BATT\_\-READ\_\-PERC}}
\index{BATT\_\-READ\_\-PERC@{BATT\_\-READ\_\-PERC}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{BATT\_\-READ\_\-PERC}]{\setlength{\rightskip}{0pt plus 5cm}\#define BATT\_\-READ\_\-PERC~1}}
\label{group__nxbot__sensors_ga61262b004f6813b955f4d0b2d6553817}


constant definition for battery\_\-read 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sensors_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sensors_ga1a0d280534953662003acd91f20071c1}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!BATT\_\-READ\_\-VOLT@{BATT\_\-READ\_\-VOLT}}
\index{BATT\_\-READ\_\-VOLT@{BATT\_\-READ\_\-VOLT}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{BATT\_\-READ\_\-VOLT}]{\setlength{\rightskip}{0pt plus 5cm}\#define BATT\_\-READ\_\-VOLT~0}}
\label{group__nxbot__sensors_ga1a0d280534953662003acd91f20071c1}


constant definition for battery\_\-read 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sensors_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sensors_ga756d8a8a2ba732eb8d918b48108bf034}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getADCRead@{sensors\_\-getADCRead}}
\index{sensors\_\-getADCRead@{sensors\_\-getADCRead}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getADCRead}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getADCRead(
\begin{DoxyParamCaption}
\item[{}]{channel}
\end{DoxyParamCaption}
)~adc\_\-read(channel)}}
\label{group__nxbot__sensors_ga756d8a8a2ba732eb8d918b48108bf034}
\hypertarget{group__nxbot__sensors_gada5c769ceb7d8b75c54cf90ab4e748f7}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getBattState@{sensors\_\-getBattState}}
\index{sensors\_\-getBattState@{sensors\_\-getBattState}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getBattState}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getBattState(
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)~battery\_\-read(BATT\_\-READ\_\-PERC)}}
\label{group__nxbot__sensors_gada5c769ceb7d8b75c54cf90ab4e748f7}
\hypertarget{group__nxbot__sensors_ga709d68c36da1e3f2b5feec8c76ed9243}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getBattVoltage@{sensors\_\-getBattVoltage}}
\index{sensors\_\-getBattVoltage@{sensors\_\-getBattVoltage}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getBattVoltage}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getBattVoltage(
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)~battery\_\-read(BATT\_\-READ\_\-VOLT)}}
\label{group__nxbot__sensors_ga709d68c36da1e3f2b5feec8c76ed9243}
\hypertarget{group__nxbot__sensors_ga704680c481c946bf98aeb484c46f30e0}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getBumpers@{sensors\_\-getBumpers}}
\index{sensors\_\-getBumpers@{sensors\_\-getBumpers}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getBumpers}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getBumpers(
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)~bumpers\_\-read()}}
\label{group__nxbot__sensors_ga704680c481c946bf98aeb484c46f30e0}
\hypertarget{group__nxbot__sensors_ga4f69888f0b0485e1c303c271272dbecf}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getDIO@{sensors\_\-getDIO}}
\index{sensors\_\-getDIO@{sensors\_\-getDIO}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getDIO}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getDIO(
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)~dio\_\-read()}}
\label{group__nxbot__sensors_ga4f69888f0b0485e1c303c271272dbecf}
\hypertarget{group__nxbot__sensors_ga4ab82b3d018ff6e6866549a065188a30}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getIR@{sensors\_\-getIR}}
\index{sensors\_\-getIR@{sensors\_\-getIR}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getIR}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getIR(
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)~ir\_\-read()}}
\label{group__nxbot__sensors_ga4ab82b3d018ff6e6866549a065188a30}
\hypertarget{group__nxbot__sensors_ga843e7932aafddffd58c4e7f2d4065bca}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-getSonar@{sensors\_\-getSonar}}
\index{sensors\_\-getSonar@{sensors\_\-getSonar}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-getSonar}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-getSonar(
\begin{DoxyParamCaption}
\item[{}]{x, }
\item[{}]{y, }
\item[{}]{s}
\end{DoxyParamCaption}
)~sonar\_\-read(x,y,s)}}
\label{group__nxbot__sensors_ga843e7932aafddffd58c4e7f2d4065bca}
\hypertarget{group__nxbot__sensors_gaa04e94731b959482fa4a5918529c9e16}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-setADCChannel@{sensors\_\-setADCChannel}}
\index{sensors\_\-setADCChannel@{sensors\_\-setADCChannel}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-setADCChannel}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-setADCChannel(
\begin{DoxyParamCaption}
\item[{}]{channel}
\end{DoxyParamCaption}
)~adc\_\-setChannel(channel)}}
\label{group__nxbot__sensors_gaa04e94731b959482fa4a5918529c9e16}
\hypertarget{group__nxbot__sensors_ga3fece7b941ca3f7239a55747bd02ce48}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-setDIO@{sensors\_\-setDIO}}
\index{sensors\_\-setDIO@{sensors\_\-setDIO}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-setDIO}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-setDIO(
\begin{DoxyParamCaption}
\item[{}]{val}
\end{DoxyParamCaption}
)~dio\_\-write(val)}}
\label{group__nxbot__sensors_ga3fece7b941ca3f7239a55747bd02ce48}
\hypertarget{group__nxbot__sensors_ga21d87617d11c161caa395ce84f987e71}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-setSonar@{sensors\_\-setSonar}}
\index{sensors\_\-setSonar@{sensors\_\-setSonar}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-setSonar}]{\setlength{\rightskip}{0pt plus 5cm}\#define sensors\_\-setSonar(
\begin{DoxyParamCaption}
\item[{}]{x, }
\item[{}]{u}
\end{DoxyParamCaption}
)~sonar\_\-write(x,u)}}
\label{group__nxbot__sensors_ga21d87617d11c161caa395ce84f987e71}


\subsection{Function Documentation}
\hypertarget{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!battery\_\-getState@{battery\_\-getState}}
\index{battery\_\-getState@{battery\_\-getState}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{battery\_\-getState}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char battery\_\-getState (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}


Reads the state of the battery, in \mbox{[}\%\mbox{]} units. 

This function returns the last calculated value for the battery state. The calculation of the state value is done in the ISR, each time a reading is complete. That means, when the interrupts are not enabled, the reading will not be actual neither accurate.

\begin{DoxyReturn}{Returns}
The battery state, from 0 to 100. 
\end{DoxyReturn}
\hypertarget{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!battery\_\-getVoltage@{battery\_\-getVoltage}}
\index{battery\_\-getVoltage@{battery\_\-getVoltage}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{battery\_\-getVoltage}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int battery\_\-getVoltage (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}


Reads the state of the battery, in \mbox{[}V\mbox{]} units. 

This function returns the last calculated value for the battery voltage. The calculation of the voltage is done in the ISR, each time a reading is complete. That means, when the interrupts are not enabled, the reading will not be actual neither accurate.

\begin{DoxyReturn}{Returns}
The battery voltage, from 0 to 600 (when using 6V battery), or to 1200 (when using 12V battery). 
\end{DoxyReturn}
\hypertarget{group__nxbot__sensors_gabfbbfb986d008991dbbe32035cbdcde6}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!battery\_\-init@{battery\_\-init}}
\index{battery\_\-init@{battery\_\-init}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{battery\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void battery\_\-init (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gabfbbfb986d008991dbbe32035cbdcde6}


Hardware initialization for the battery module. 

Configures the ADC, enabling channel ADC0. VREF is the supply voltage (expected 5V). \hypertarget{group__nxbot__sensors_gabf908968d26d8f291a60846d6dd51251}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!battery\_\-ledEnable@{battery\_\-ledEnable}}
\index{battery\_\-ledEnable@{battery\_\-ledEnable}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{battery\_\-ledEnable}]{\setlength{\rightskip}{0pt plus 5cm}void battery\_\-ledEnable (
\begin{DoxyParamCaption}
\item[{unsigned char}]{en}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gabf908968d26d8f291a60846d6dd51251}


Function used to write the state of the battery-\/LED, located in the rear of NXBot. 

CAUTION!: This function is only used for debugging purposes. The LED is automatically activated, if the battery is full-\/charged. If the battery charge is below some predefined limit (5,2V), the LED will be automatically deactivated.


\begin{DoxyParams}{Parameters}
{\em en} & 1 for enabling the LED, 0 for disabling. Instead of these values, use either ON or OFF constants, defined globally in Makefile. \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__sensors_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!battery\_\-read@{battery\_\-read}}
\index{battery\_\-read@{battery\_\-read}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{battery\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int battery\_\-read (
\begin{DoxyParamCaption}
\item[{unsigned char}]{type}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gaec4ef3b620c24ee1c4ea58e26fe93cb3}


Read the state of the battery, wether voltage or percentage. 

This function is the same as \hyperlink{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState()} or \hyperlink{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage()}, and is included for compatibility issues (each sensor module should have a \_\-read() function). \begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState} \hyperlink{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage}
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em type} & Defines which value will be returned. Use BATT\_\-READ\_\-VOLT or BATT\_\-READ\_\-PERC to obtain Voltage or Percent, respectively. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
same as in \hyperlink{group__nxbot__sensors_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState()} or \hyperlink{group__nxbot__sensors_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage()} 
\end{DoxyReturn}
\hypertarget{group__nxbot__sensors_gac5ec1d578591899e43c3515d05e573b7}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-init@{sensors\_\-init}}
\index{sensors\_\-init@{sensors\_\-init}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void sensors\_\-init (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gac5ec1d578591899e43c3515d05e573b7}
\hypertarget{group__nxbot__sensors_gafbed7bde16bf6f2535f0792084773b17}{
\index{nxbot\_\-sensors@{nxbot\_\-sensors}!sensors\_\-readAll@{sensors\_\-readAll}}
\index{sensors\_\-readAll@{sensors\_\-readAll}!nxbot_sensors@{nxbot\_\-sensors}}
\subsubsection[{sensors\_\-readAll}]{\setlength{\rightskip}{0pt plus 5cm}void sensors\_\-readAll (
\begin{DoxyParamCaption}
\item[{{\bf sensors\_\-t} $\ast$}]{sens}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sensors_gafbed7bde16bf6f2535f0792084773b17}
